﻿using System;
using System.Threading;
using System.Threading.Tasks;

namespace AsyncMethod
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = new Program();
            var n = Program.ReadInt(p);
            Console.WriteLine("Here we go: {0}", n);
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }

        private static async Task<int> ReadInt(Program p)
        {
            return await p.MethodAsync();
        }

        async Task<int> MethodAsync()
        {
            var task = Task.Run(() => this.RandomInt());
            return await task;
        }

        private int RandomInt()
        {
            var random = new Random();
            Thread.Sleep(random.Next(900) + 100);
            var result = random.Next(100);
            return result;
        }

        //private int CalcFibonaci(int n)
        //{
        //    var result = n == 0 ? 0 : (n == 1 ? 1 : this.CalcFibonaci(n - 1) + this.CalcFibonaci(n - 2));
        //    return result;
        //}
    }
}
